#!/bin/bash

# Apply database migrations
echo "Apply database migrations"
# python manage.py db init
if [ -f "./migrations/env.py" ];then
echo "迁移文件存在"
else
echo "迁移文件不存在"
python3.8 manage.py db init
fi
python3.8 manage.py db migrate
python3.8 manage.py db upgrade

# Create super user if not exists
python3.8 fake.py

# Start task sender
# TODO disabled
# nohup python manage.py sender 10 &

# queue task to upload log file
nohup celery -A celery_task worker -c 1 -B -l info >celery.log 2>&1 &

# celery -A celery_task worker -l info

# echo "======Celery beat scheduled task on background======"
# nohup celery -A backend worker -n tams_worker -c 1 -B -Q tams -l debug >celery_beat.log 2>&1 &

# Start server
# echo "Starting server"
# python manage.py runserver
# daphne -b 0.0.0.0 -p 8000 backend.asgi:application
